package com.kitty.game.team.model;


import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.Objects;

@Data
public class Team {
    private int id;
    private String name;
    private Date createTime;
    private ArrayList<Member> list;
    private ArrayList<Member> shouhus;
    private int lastTeamId;

    /**
     * 判断对应角色id是否是队长
     * @param roleId
     * @return
     */
    public boolean isLeader(int roleId) {
        if (list == null || list.isEmpty()) {return false;}
        /**列表第1个是队长*/
        if (list.get(0) == null) {return false;}
        return list.get(0).getRoleId() == roleId;
    }
    /**获得队长的角色ID*/
    public int getLeaderRoleId() {
        if (list == null || list.isEmpty()) {return 0;}
        if (list.get(0) == null) {return 0;}
        return list.get(0).getRoleId();
    }

    /**
     * 获得队长的角色UID
     */
    public long getLeaderUid() {
        if (list == null || list.isEmpty()) {return 0;}
        if (list.get(0) == null) {return 0;}
        return list.get(0).getUid();
    }


    /**取队员对象*/
    public Member getMember(int roleId){
        for (Member member:list) {
            if(member.getRoleId()==roleId){
                return member;
            }
        }
        return null;
    }

    /**获得队伍所有队员名字(暂离成员除外)*/
    public String getMemberNames() {
        StringBuilder stringBuilder = new StringBuilder();
        if (list != null) {
            for (Member member:list) {
                if (member == null) {continue;}
                if (!member.isInTeam()) {continue;}
                if (stringBuilder.length() > 0) {
                    stringBuilder.append("、");
                }
                stringBuilder.append(member.getName());
            }
        }

        return stringBuilder.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Team)) return false;
        Team team = (Team) o;
        return id == team.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
